package UILag;
import ctrLag.*;
import modelLag.*;
import java.util.Scanner;

/**
 * Write a description of class FriendsUI here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class CopyUI
{
    // instance variables - replace the example below with your own
    private CopyCtr copyCtr;

    /**
     * Constructor for objects of class FriendsUI
     */
    public CopyUI()
    {
        // initialise instance variables
        copyCtr = new CopyCtr();
    }

    /**
     * An example of a method - replace this comment with your own
     * 
     * @param  y   a sample parameter for a method
     * @return     the sum of x and y 
     */
    public void start()
    {
        copyMenu();
    }
    
    public void copyMenu()
    {
       boolean exit = false;
       while(!exit)//that is: while exit is false
       {
          int choise = writeCopyMenu(); 
          if(choise == 1)
          {
              createCopy();
          }
          
          else if(choise == 2)
          {
              findCopy();
          }
          
          else if(choise == 3)
          {
              deleteCopy();
          } 
          else if (choise ==4){
              System.out.println("Change info");
            }
          
          
          else
          {exit = true;}
         }//end else    
       }//end while
       
    public int writeCopyMenu()
    {      // makes an object keyboard to read input from the screen
            Scanner keyboard = new Scanner(System.in);
            System.out.println("*** Copy Menu ***");
            System.out.println(" (1) Create Copy");
            System.out.println(" (2) Find Copy");
            System.out.println(" (3) Remove Copy");
            System.out.println(" (4) Change Copy info");
            System.out.println(" (5) Close");
            System.out.print("\n Make your choice: ");
            
            int choise = keyboard.nextInt();
            if(choise > 5 || choise == 0)
            {
               System.out.println("ERROR ERROR ERROR!! Number:" + choise +" is not a valid number.......");
               return writeCopyMenu();
            }
            else
            return choise;
    }
   
    public int inputSerialNumber()
    {
        boolean ok = false;
        int serialNumber = 0;
        while(!ok)
        {
         // makes an object keyboard to have input from the console
         Scanner keyboard = new Scanner(System.in);
         System.out.println(" Enter the serial number of the copy: ");
            try{
                 serialNumber = keyboard.nextInt();
                 ok = true;
            }
            catch (Exception e)
                {
                 System.out.println("Input must be a number, please try again");
                 String input = keyboard.nextLine();
            }
        }//end while
        return serialNumber;
    }
    
    public String inputPurchaseDate()
    {
        // makes an object keyboard to read input from the console
        Scanner keyboard = new Scanner(System.in);
        System.out.println(" Enter the purchase date of the copy: ");
        String purchaseDate = keyboard.nextLine();
        return purchaseDate;
    }
    
    public double inputPurchasePrice()
    {
        boolean ok = false;
        double purchasePrice = 0;
        while(!ok)
        {
         // makes an object keyboard to have input from the console
         Scanner keyboard = new Scanner(System.in);
         System.out.println(" Enter the purchase price of the copy: ");
            try{
                 purchasePrice = keyboard.nextInt();
                 ok = true;
            }
            catch (Exception e)
                {
                 System.out.println("Input must be a number, please try again");
                 String input = keyboard.nextLine();
            }
        }//end while
        return purchasePrice;
    }
    
    public void createCopy()
    {
        int serialNumber = inputSerialNumber();
        String purchaseDate = inputPurchaseDate();
        double purchasePrice = inputPurchasePrice();
        
        
        copyCtr.addCopy(serialNumber, purchaseDate, purchasePrice);
    }
    
    private Copy findCopy(){
        int serialNumber = inputSerialNumber();
        Copy copy = copyCtr.findCopy(serialNumber);
        copy.printCopyInfo();
        return copy;
    }
    
    public void showSerialNumber(int serialNumber){
        System.out.println("Copy name:  " +serialNumber);
    }
    
    public void deleteCopy(){
        int serialNumber = inputSerialNumber();
        Copy copy = copyCtr.deleteCopy(serialNumber);
    }
}